use bevy::app::AppExit;
use bevy::prelude::MessageWriter;
use clap::Parser;

use crate as bevy_console;
use crate::ConsoleCommand;

/// Exits the app
#[derive(Parser, ConsoleCommand)]
#[command(name = "exit")]
pub struct ExitCommand;

pub fn exit_command(mut exit: ConsoleCommand<ExitCommand>, mut exit_writer: MessageWriter<AppExit>) {
    if let Some(Ok(_)) = exit.take() {
        exit_writer.write(AppExit::Success);
        exit.ok();
    }
}
